package top.korori.api.controller;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import top.korori.common.utils.ImageUtils;
import top.korori.oss.service.CosService;

import java.io.IOException;

@RestController()
@RequestMapping("/test")
public class TestController {

    @Autowired
    private CosService cosService;

    @Getter
    @Setter
    static class Param {
        @ApiModelProperty("image")
        private String image;
    }

    @PostMapping("/image")
    public String test(@RequestBody Param param){
        MultipartFile multipartFile = ImageUtils.base64ToMultipartFile(param.image);
        try {
            cosService.putObj(multipartFile.getInputStream(),"avatar/"+multipartFile.getOriginalFilename());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return "你好";
    }
}
